home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 270_01 / est.doc < prev    next >
Text File  |  1980-01-01  |  5KB  |  94 lines

  1.          EST:  finding the ..est file(s) on your disk.
  2.  
  3. The EST program finds the largEST, smallEST, oldEST, newEST files.  It was
  4. suggested by a colleague who needed to know which were the largest files on
  5. his hard disk.  He wanted to identify a set of files which might be potential
  6. candidates for deletion to free up space on his disk.  No existing utility
  7. (that we knew of) provided this information so I decided to write one (nature
  8. abhors a vacuum).
  9.  
  10. This simple utility illustrates the use of a number of powerful functions from
  11. the Microsoft C run-time library.
  12.  
  13. * _splitpath
  14. * _makepath
  15. * _dos_findfirst
  16. * _dos_findnext
  17.  
  18.  
  19. _splitpath breaks up a path specification into its component parts (drive,
  20. directory, file name, and extension).  _makepath reassembles a path name from
  21. supplied parts.  If the NULL pointer is supplied as a pointer to one of the
  22. component parts of the path, both functions will ignore that component in
  23. building or decomposing a path.
  24.  
  25. EST uses _splitpath and _makepath to separate the file name and extension from
  26. the supplied path parameter.  If no path was given, the default is "*.*" in
  27. the current directory.
  28.  
  29. Path names in MS-DOS are essentially ambiguous.  You cannot tell by scanning
  30. the name whether it represents a file or a directory.  Therefore, if you
  31. specify
  32.  
  33.           EST/o guess
  34.  
  35. EST cannot tell whether you want just file name 'guess' or the set
  36. 'guess\*.*'.  To remove this ambiguity, we require that any path which is a
  37. directory must end with the back slash ('\').
  38.  
  39.  
  40. Finding Files
  41.  
  42. _dos_findfirst finds the first file whose name and attributes match supplied
  43. ambiguous name and attribute parameters.  Unfortunately, the documentation
  44. does not clearly state how to find a subdirectory.  For the path name, do you
  45. specify:
  46.  
  47.      \MYDIR or \MYDIR\* or \MYDIR\*.* or what?
  48.  
  49. It turns out that "\MYDIR\*" and \MYDIR\*.*" will both find subdirectories of
  50. MYDIR.  All of the above will work as parameters to DIR from the DOS prompt.
  51. Only "DIR \MYDIR\*." will select directories and other files having no
  52. extension.  However, both "\MYDIR\*" and "\MYDIR\*." will return files with no
  53. extension when used as parameters to _dos_findfirst.
  54.  
  55. The documentation for _dos_findfirst implies that only files or directories
  56. matching the supplied attributes will be returned.  Actually, the logic for
  57. building the set of entries passed back by these functions is:
  58.  
  59. 1.   Add to the set all files which match the ambiguous path name (including
  60.      system, hidden, directory and volid files).
  61. 2.   If _A_HIDDEN is not chosen, remove all hidden files from the set.
  62. 3.   If _A_SYSTEM is not chosen, remove all system files from the set.
  63. 4.   If _A_SUBDIR is not chosen, remove all subdirectory files from the set.
  64. 5.   If _A_VOLID is chosen alone, remove all but the volid file.
  65. 6.   If _A_VOLID is not chosen, remove the volid file.
  66.  
  67. The attributes _A_RDONLY and _A_ARCH have no effect on directory searches.
  68. That is, if you are searching for all files which have the _A_RDONLY or
  69. _A_ARCH bit set in the attribute, you must test each file returned for this
  70. condition, _dos_findfirst and _dosfindnext will not select these out for you.
  71. The only directory search which selects only the file which exactly matches
  72. the attribute of the search is _A_VOLID.  However, if _A_VOLID is used in
  73. combination with any of (_A_HIDDEN, _A_SYSTEM, _A_SUBDIR), it will return all
  74. matching files plus the volid file.  Therefore, _dos_findfirst and
  75. _dos_findnext may return many files which have attributes which do not match
  76. those you are searching for.  So, you must test the attributes of each
  77. returned file to ensure that a true match is made.
  78.  
  79.  
  80. Searching Subdirectories
  81.  
  82. Unfortunately, to find all subdirectories in a directory requires a separate
  83. search since the first criterion is that the ambiguous file reference must be
  84. matched.  As noted above, subdirectories may be matched by "*".  The function
  85. findfiles will call itself recursively if subdirectory search is required and
  86. one is found.  This is like a depth-first tree search.  Each file found must
  87. be tested for the _A_SUBDIR attribute since more than just subdirectories will
  88. be returned.
  89.  
  90. Once no more subdirectories are found, findfiles begins another search, this
  91. time using the file path specification supplied when est was invoked.  All of
  92. the files returned are tested for inclusion in the sets oldest, newest,
  93. largest, smallest as specified by est options.
  94.